/*
 ***************************************************************************************
 * All rights Reserved, Designed By RTF
 * @Title:  KafkaProducerConfiger.java
 * @Package com.rtf.repair.mq.kafka.producer
 * @Description: 1.rocket 生产者配置
 * 				 2.获取属性
 * 				 3.生成rocket生产者管理器控制生命周期
 * 				 4.创建适配器
 * @author: 司福林
 * @date:   2020-10-17 16:35:03
 * @version V1.0
 * @Copyright: 2020 RTF. All rights reserved.
 * 注意：本内容仅限于公司内部使用，禁止外泄以及用于其他的商业目
 *  ----------------------------------------------------------------------------------
 * 文件修改记录
 *     文件版本：         修改人：             修改原因：
 ***************************************************************************************
 */
package com.rtf.framework.mq.kafka.producer;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.rtf.framework.mq.common.CommonConstants;

/**
 *
 *
 * @ClassName:  KafkaProducerConfiger
 * @author: 67077
 * @date:   2020-10-17 16:38:10
 * @since:  v1.0
 */
@ConditionalOnProperty(prefix = "app.mq.producer", value = "type", havingValue = CommonConstants.MQ_TYPE_KAFKA)
@Configuration
public class KafkaProducerConfiger {

	/**
	 * Rocket mq producer properties.
	 *
	 * @return the rocket mq producer properties
	 */
	@Bean
	@ConfigurationProperties(prefix = "app.mq.producer.kafka")
	public KafkaProducerProperties kafkaProducerProperties() {
		return new KafkaProducerProperties();
	}

	/**
	 * Rocket mq Manager.
	 *
	 * @param kafkaProducerProperties the rocket mq producer properties
	 * @return the rocket mq manager
	 */
	@Bean(destroyMethod = "destroy")
	public KafkaManager kafkaFactory(KafkaProducerProperties kafkaProducerProperties) {
		KafkaManager kafkaFactory = new KafkaManager(kafkaProducerProperties);
		kafkaFactory.init();
		kafkaFactory.start();
		return kafkaFactory;
	}

	/**
	 * Rocket mq producer adaptor.
	 *
	 * @param kafkaFactory the rocket mq factory
	 * @return the rocket mq producer adaptor
	 */
	@Bean
	public KafkaProducerAdaptor kafkaProducerAdaptor(KafkaManager kafkaFactory) {
		KafkaProducerAdaptor kafkaProducerAdaptor = new KafkaProducerAdaptor(kafkaFactory.getProducer());
		return kafkaProducerAdaptor;
	}
}
